import { IP, zs } from "./url";
export function replaceImg(str) {
  let newStr = str.replace(/<img.*?src="(.*?)".*?>/gi, keyword => {
    keyword = keyword.replace(/src=[\'\"]?([^\'\"]*)[\\/'\"]?/gi, key => {
      key = key.split('"')[1];

      if (
        /((http|https):\/\/([\w.]+\/?)\S*)/i.test(key) ||
        /^file/i.test(key)
      ) {
        return `src="${key}"`;
      } else {
        return `src="${IP + key}"`;
      }
    });
    return keyword;
  });
  return newStr;
}
export function replaceA(str) {
  let newStr = str.replace(/<a[^>]+href=['"]\/([^'"]*)['"]>/gi, keyword => {
    keyword = keyword.split('"')[1];

    return `<a href="${zs + keyword}">`;
  });

  return newStr;
}
export function replaceVideo(str) {
  let newStr = str.replace(/<video.*>.*video>/gi, keyword => {
    keyword = keyword.replace(/preload="none"/gi, key => {
      return ` preload="auto"`;
    });
    // console.log(keyword);
    return keyword;
  });
  return newStr;
}
